package com.sojson.service.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sojson.dao.DictDataDao;
import com.sojson.entity.po.DictData;
import com.sojson.service.DictDataService;

/**
 * 字典类型描述表Service实现类
 * 
 * @author liu
 * @date 2021-04-13
 */
@Service
public class DictDataServiceImpl implements DictDataService {

    @Resource
    private DictDataDao dictDataDaoImpl;

    /**
     * 单条插入
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public int insert(DictData dictData) {
        int insert = 0;
        // synchronized (INSERT_LOCK) {
        // DictData dict = new DictData();
        // dict.setCode(dictData.getCode());
        // dict.setValue(dictData.getValue());
        // int countByDto = countByDto(dict);
        // if (countByDto > 0) {
        // throw new TransException("字典类型值已存在！");
        // }

        insert = dictDataDaoImpl.insert(dictData);
        // }
        return insert;
    }

    /**
     * 批量插入
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public int insertList(DictData dictData) {
        int insertList = dictDataDaoImpl.insertList(dictData.getDictDatas());
        return insertList;
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public int deleteByDto(DictData dictData) {
        int deleteByDto = dictDataDaoImpl.deleteByDto(dictData);
        return deleteByDto;
    }

    /**
     * 统计全部数量
     * 
     * @return
     * @throws SQLException
     */
    @Override
    public int countAll() {
        int countAll = dictDataDaoImpl.countAll();
        return countAll;
    }

    /**
     * 查询所有
     * 
     * @return
     * @throws SQLException
     */
    @Override
    public List<DictData> findAll() {
        List<DictData> findAll = dictDataDaoImpl.listAll();
        return findAll;
    }

    /**
     * 根据对象统计数量
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public int countByDto(DictData dictData) {
        int countByDto = dictDataDaoImpl.countByDto(dictData);
        return countByDto;
    }

    /**
     * 根据对象查询
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public List<DictData> findByDto(DictData dictData) {
        List<DictData> findByDto = dictDataDaoImpl.listByDto(dictData);
        return findByDto;
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     * @throws SQLException
     */
    @Override
    public int deleteById(Integer id) {
        int deleteById = dictDataDaoImpl.deleteById(id);
        return deleteById;
    }

    /**
     * 通过id列表删除(物理删除)
     * 
     * @param ids
     * @return
     * @throws SQLException
     */
    @Override
    public int deleteByIdList(ArrayList<Integer> ids) {
        int deleteByIdList = dictDataDaoImpl.deleteByIdList(ids);
        return deleteByIdList;
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public int updateById(DictData dictData) {
        int updateById = dictDataDaoImpl.updateById(dictData);
        return updateById;
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public int updateStaticByIdList(DictData dictData) {
        int updateStaticByIdList = dictDataDaoImpl.updateStaticByIdList(dictData);
        return updateStaticByIdList;
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public int updateChangeByIdList(DictData dictData) {
        int updateChangeByIdList = dictDataDaoImpl.updateChangeByIdList(dictData.getDictDatas());
        return updateChangeByIdList;
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public int updatePartialById(DictData dictData) {
        int updatePartialById = 0;
        // synchronized (INSERT_LOCK) {
        // DictData dict = new DictData();
        // dict.setCode(dictData.getCode());
        // dict.setValue(dictData.getValue());
        // int countByDto = countByDto(dict);
        // if (countByDto > 0) {
        // throw new TransException("字典类型值已存在！");
        // }

        updatePartialById = dictDataDaoImpl.updatePartialById(dictData);
        // }
        return updatePartialById;
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public int updateStaticPartialByIdList(DictData dictData) {
        int updateStaticPartialByIdList = dictDataDaoImpl.updateStaticPartialByIdList(dictData);
        return updateStaticPartialByIdList;
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public int updateChangePartialByIdList(DictData dictData) {
        int updateChangePartialByIdList = dictDataDaoImpl.updateChangePartialByIdList(dictData.getDictDatas());
        return updateChangePartialByIdList;
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     * @throws SQLException
     */
    @Override
    public DictData findById(Integer id) {
        DictData findById = dictDataDaoImpl.findById(id);
        return findById;
    }

    /**
     * 通过id列表查询
     * 
     * @param ids
     * @return
     * @throws SQLException
     */
    @Override
    public ArrayList<DictData> findByIdList(ArrayList<Integer> ids) {
        ArrayList<DictData> findByIdList = dictDataDaoImpl.findByIdList(ids);
        return findByIdList;
    }

    /**
     * 通过对象查询id列表
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public ArrayList<Integer> findIdByDto(DictData dictData) {
        ArrayList<Integer> findIdByDto = dictDataDaoImpl.findIdByDto(dictData);
        return findIdByDto;
    }

    /**
     * 清空数据(物理清空)
     * 
     * @throws SQLException
     */
    @Override
    public void clear() {
        dictDataDaoImpl.clear();
    }

    /**
     * 通过code查询
     * 
     * @param dictData
     * @return
     * @throws SQLException
     */
    @Override
    public List<DictData> findByCode(DictData dictData) {
        return dictDataDaoImpl.findByCode(dictData);
    }

    /**
     * 通过code列表删除(物理删除)
     * 
     * @param codes
     * @return
     * @throws SQLException
     */
    @Override
    public List<DictData> deleteByCodeList(List<String> codes) {
        return dictDataDaoImpl.deleteByCodeList(codes);
    }

}